home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / interpol < prev    next >
Text File  |  1995-03-31  |  5KB  |  111 lines

  1. Article 2297 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!rex!ames!haven!udel!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!paul+
  3. From: paul+@andrew.cmu.edu (Paul J. Dujmich)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Interpolation Program
  6. Message-ID: <gbDcr7y00UzxI0lVc0@andrew.cmu.edu>
  7. Date: 12 Nov 90 11:55:51 GMT
  8. Organization: Computing Systems, Carnegie Mellon, Pittsburgh, PA
  9. Lines: 98
  10.  
  11. Here is a little ditty I wrote this term for Thermodynamics.
  12. It does interpolation between 2 numbers (like 2 values from the steam
  13. tables). The program looks at the number of decimal places in the values
  14. you enter, and displays the interpolated result with that number of
  15. decimal places. The 48 is returned to your decimal place setting upon
  16. exit from the program. It has proved to be a real time saver when a lot
  17. of interpolation must be performed ie thermodynamics, fudging fake data
  18. points in lab etc.
  19.  
  20. Paul J. Dujmich
  21. Electrical/Computer Engineering Dept
  22. Carnegie Mellon University
  23. -------------------------------------------------------------------------------
  24. %%HP: T(3)A(R)F(.);
  25. @ PROGRAM NAME:       intp
  26. @ DATE:               9-18-90  Paul Dujmich (pauld(at sign)fs1.ece.cmu.edu)
  27. @ PURPOSE:            Does Interpolation Between two values
  28. @ ARGUMENTS:          Level 5: low reference
  29. @                     Level 4: value at low reference
  30. @                     Level 3: high reference
  31. @                     Level 2: value at high reference
  32. @                     Level 1: desired point between low reference and
  33. @                              high reference.
  34. @
  35. @      Example:
  36. @                 at 100 value = 10
  37. @                 at 200 value = 8.8
  38. @
  39. @                 Find the value at 155.67
  40. @
  41. @                 Enter to stack:  100
  42. @                                  10
  43. @                                  200
  44. @                                  8.8
  45. @                                  155.67
  46. @
  47. @                 Press 'INTP'  (The Interpolated value of 9.3 is displayed)
  48. @ (Store program in a variable called 'INTP')
  49. @ Note: The interpolated value displayed will have the same number of
  50. @       decimal places as the two values entered.
  51.  
  52.  
  53.  
  54. \<< 0 0 0 \-> lr lv hr hv p dp ndp tst
  55.   \<< -45 FS? 'dp' STO+          @Test flags -45 to -48 to determine
  56.       -46 FS? 2 * 'dp' STO+      @how many decimal places are selected
  57.       -47 FS? 4 * 'dp' STO+      @upon entry into program
  58.       -48 FS? 8 * 'dp' STO+      @save in dp
  59.  
  60.      @ determine which value (lv or hv) has biggest fractional part
  61.      @ the one with biggest fractional part is used to determine the
  62.      @ number of decimal places to set the display to.
  63.  
  64.       IF 'FP(lv) > FP(hv)' THEN lv 'tst' STO
  65.          ELSE hv 'tst' STO
  66.       END
  67.  
  68.  
  69.     @***** do this if exponent is negative ****************************
  70.     IF 'XPON(tst)<0'              @if low value has a negative exponent
  71.         THEN tst XPON NEG         @imvert it and put it in ndp
  72.         'ndp' STO+
  73.         tst MANT FP               @get fraction part of Matissa
  74.  
  75.         ELSE                     @do this for positive exponents
  76.             tst MANT FP           @get fractional part of mantissa
  77.             tst XPON ALOG *       @multiply it by 10^(exponent of lv)
  78.         END
  79.  
  80.  
  81.     @*** do this for both positive and negative exponents ********
  82.     WHILE  FP DUP 0 >            @ shift left 1 decimal place
  83.           REPEAT .1 /            @add 1 to decimal place count
  84.           1 'ndp' STO+
  85.           END
  86. DROP                             @set decimal places for display
  87. ndp FIX
  88.  
  89. p lr -                           @low reference - desired point
  90. hr lr - /                        @high reference - low reference, get factor
  91.     IF 'hv>lv'                   @ if high value > low value
  92.          THEN hv lv - *          @get difference and multiply by factor
  93.          lv +                    @add it to low value
  94.          'lv' STO                @save interpolated value
  95.          "Int Val = "
  96.          lv +
  97.          CLLCD 1 DISP 7 FREEZE   @display it on screen
  98.  
  99.     ELSE lv hv - *               @low value - high value *factor
  100.          NEG lv +                @make it minus, multiply with factor
  101.          'lv' STO                @save interpolated value
  102.          "Int Val = "
  103.          lv +
  104.          CLLCD 1 DISP 7 FREEZE   @display it on screen
  105.          END
  106. dp FIX                           @restore old decimal point setting
  107.   \>>
  108. \>>
  109.  
  110.  
  111.